package com.wc.alorithm_blue_bridge._字符串.KMP.Q3010;

import java.util.*;
/**
 * @Author congege
 * @Description
 * 幸运字符串
 * https://www.lanqiao.cn/problems/3010/learning/?page=1&first_category_id=1
 * @Date Created in 2023/12/1-11:02
 */
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.nextLine()) / 2 + 2;
        String s = scan.nextLine();
        int ans = 0;
        for(int i = 1; i <= n; i++){
            String compare = s.substring(0,i);
            if(kmp(s,compare,i) == -1){
                ans = i - 1;
                break;
            }
        }
        System.out.println(ans);
    }

    private static int kmp(String str,String sub,int pos){
        int lenSub = sub.length();
        int lenStr = str.length();
        if(pos < 0 || pos >= lenStr || lenSub > lenStr - pos){
            return -1;
        }
        int[] nextVal = new int[lenSub];
        getNextVal(sub,nextVal);
        int i = pos;
        int j = 0;
        while(i < lenStr && j < lenSub){
            if(j == -1 || str.charAt(i) == sub.charAt(j)){
                i++;
                j++;
            } else {
                j = nextVal[j];
            }
        }
        if(j >= lenSub){
            return i - j;
        }
        return -1;
    }

    private static void getNextVal(String sub,int[] nextVal){
        int lenSub = nextVal.length;
        int[] next = new int[lenSub];
        nextVal[0] = next[0] = -1;
        if(lenSub < 2){
            return;
        }
        next[1] = 0;
        int i = 2;
        int k;
        while(i < lenSub){
            k = next[i - 1];
            while(k != -1 && sub.charAt(i - 1) != sub.charAt(k)){
                k = next[k];
            }
            next[i] = k + 1;
            i++;
        }
        getNextVal(sub,next,nextVal);
    }

    public static void getNextVal(String sub,int[] next,int[] nextVal){
        int lenSub = nextVal.length;
        nextVal[0] = -1;

        int i = 1;
        while(i < lenSub){
            if(sub.charAt(i) == sub.charAt(next[i])){
                nextVal[i] = nextVal[next[i]];
            }else {
                nextVal[i] = next[i];
            }
            i++;
        }
    }
}
